package org.lcc.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.lcc.model.entity.StudentMistakeEntity;
import org.lcc.model.dto.*;
import org.lcc.model.entity.User;

import java.util.List;
import java.util.Map;

@Mapper
public interface UserMapper extends BaseMapper<User> {
    //重置密码
    User forget(@Param("schoolNumber") String schoolNumber, @Param("username") String username);

    //登录查询信息
    User login(@Param("username") String username);

    //注册
    Boolean signin(@Param("signInRequest") Sign_inRequest signInRequest);

    //修改密码
    int editPassword(@Param("hashedPassword") String hashedPassword, @Param("school_number") String schoolNumber);

    //创建班级
    int createClass(CreateRequest createRequest);

    //创建关联
    int createteacher_class(@Param("teacherNumber") String teacherNumber, @Param("classId") int classId);

    //批量插入user
    void batchInsertUsers(@Param("list") List<Sign_inRequest> users);

    //批量插入到student_class_link
    void insertstudent_class_link(@Param("list") List<Sign_inRequest> dataList, @Param("classId") Integer classId);

    //更新用户信息
    Boolean updateUser(UserDto userDto);

    //通过老师工号查询班级id和班级姓名
    List<ClassInfoDto> getClassByTeacherNumber(@Param("teacherNumber") String teacherNumber);

    //班级ID查询其学生信息
    List<UserDto> getStudentList(@Param("classIds") List<Integer> classIds);
    //通过老师工号查询班级id
    List<Integer> getClassByTeacherNumberList(@Param("teacherNumber") String teacherNumber);

    //新增考生
    Boolean addStudent(AddStudentRequest request);

    //新增考生班级关联
    Boolean addStudentClassLink(@Param("school_number") String schoolNumber, @Param("class_id") Integer classId);

    //按班级筛选学生
    List<UserDto> filterStudentsByClass(@Param("teacherNumber") String teacherNumber, @Param("classId") Integer classId, @Param("keyword") String keyword, @Param("status") String status,@Param("offset") int offset,@Param("pageSize") int pageSize);
    //获取筛选后的学生总数
    Integer getFilteredStudentCount(@Param("teacherNumber") String teacherNumber, @Param("classId") Integer classId, @Param("keyword") String keyword, @Param("status") String status);

    //删除学生信息user
    int deleteBySchoolNumber(String schoolNumber);
//删除学生信息student_class_link
    Integer deleteBySchoolNumber_Class(String schoolNumber);
//删除学生信息exam_record
    Integer deleteBySchoolNumber_Exam(String schoolNumber);
//删除学生的答题记录
    Integer deleteBySchoolNumber_question(String schoolNumber);
//删除学生的考试通知记录
    Integer deleteBySchoolNumber_Ecamlist(String schoolNumber);

    // 批量激活学生
    void activateStudents(List<String> schoolNumbers);

    // 批量禁用学生
    void disableStudents(List<String> schoolNumbers);

    // 批量重置密码
    void resetStudentsPassword(@Param("schoolNumbers") List<String> schoolNumbers, @Param("hashedPassword") String hashedPassword);

    // 删除学生的班级关联
    void deleteStudentsClassLinks(@Param("schoolNumbers") List<String> schoolNumbers);

    // 批量插入学生的班级关联
    void insertStudentsClassLinks(@Param("schoolNumbers") List<String> schoolNumbers, @Param("classId") Integer classId);

    // 获取学生班级信息
    Map<String, Object> getStudentClass(@Param("schoolNumber") String schoolNumber);

    List<StudentMistakeEntity> getWrongQuestionList();
    @Select("SELECT DISTINCT class_id from student_class_link where school_number=#{schoolNumber}")
    List<Integer> selectClassByUserId(@Param("schoolNumber") String schoolNumber);
}
